<template>
  <el-dialog modal-append-to-body title="保存图表" :close-on-click-modal="false" :visible.sync="visible" @close="cancel" :show="show" width="400px">
    <el-form ref="form" size="mini" class="demo-form-inline" label-width="70px">
      <el-form-item label="图表名称" prop="name" placeholder="请输入图表名称">
        <el-input v-model="name"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="cancel">取 消</el-button>
      <el-button size="mini" type="primary" @click="addtag">确 定</el-button>
    </div>

  </el-dialog>
</template>

<script>
import { createNamespacedHelpers } from 'vuex';
const { mapMutations, mapState } = createNamespacedHelpers('charts')
export default {
  name: 'addPackageDialog',
  inheritAttrs: false,
  props: {
    show: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      visible: this.show,
      name: ''
    }
  },
  methods: {
    addtag () {
      this.setChartsConData({ name: this.name })
      this.$emit('saveEndCharts', this.name)
      this.$emit('update:show', false)
      this.$refs.form.resetFields()
    },
    cancel () {
      this.$refs.form.resetFields()
      this.$emit('update:show', false)
    },
    ...mapMutations(['setChartsConData'])
  },
  computed: {
    ...mapState(['chartsConData'])
  },
  watch: {
    show (val) {
      this.visible = val
      if (val) {
        this.name = this.chartsConData.title
      }
    }
  }
}
</script>

<style scoped>
</style>
